﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using cndp.Model;

namespace cndp.View
{
    public partial class FormShowHighscore : Form
    {
        public FormShowHighscore()
        {
            InitializeComponent();
        }

        public void UpdateHighScoreLabels(BindingList<Event> eventList, int rowOfEvent)
        {
            labelHSManOrWomen.Text = eventList[rowOfEvent].Gender;
            labelHSheight.Text = eventList[rowOfEvent].JumpHeight + @" meter";
            labelHSklass.Text = eventList[rowOfEvent].Bracket;

            labelHSdivername1.Text = eventList[rowOfEvent].HighScore[0].Key.Name;
            labelHSResult1.Text = eventList[rowOfEvent].HighScore[0].Value.ToString();
            if (eventList[rowOfEvent].CoupleBool)
            {
                labelHScontestname.Text = @"Parhopp";
            }
            else
            {
                labelHScontestname.Text = @"Singelhopp";
            }


            if (eventList[rowOfEvent].HighScore.Count >= 2)
            {
                labelHSdivername2.Text = eventList[rowOfEvent].HighScore[1].Key.Name;
                labelHSResult2.Text = Math.Round(eventList[rowOfEvent].HighScore[1].Value, 1).ToString();
                labelHSdif2.Text = @"-" +
                                   Math.Round(
                                       (eventList[rowOfEvent].HighScore[0].Value -
                                        eventList[rowOfEvent].HighScore[1].Value), 1);
            }

            if (eventList[rowOfEvent].HighScore.Count >= 3)
            {
                labelHSdivername3.Text = eventList[rowOfEvent].HighScore[2].Key.Name;
                labelHSResult3.Text = Math.Round(eventList[rowOfEvent].HighScore[2].Value, 1).ToString();
                labelHSdif3.Text = @"-" +
                                   Math.Round(
                                       (eventList[rowOfEvent].HighScore[0].Value -
                                        eventList[rowOfEvent].HighScore[2].Value), 1);
            }

            if (eventList[rowOfEvent].HighScore.Count >= 4)
            {
                labelHSdivername4.Text = eventList[rowOfEvent].HighScore[3].Key.Name;
                labelHSResult4.Text = Math.Round(eventList[rowOfEvent].HighScore[3].Value, 1).ToString();
                labelHSdif4.Text = @"-" +
                                   Math.Round(
                                       (eventList[rowOfEvent].HighScore[0].Value -
                                        eventList[rowOfEvent].HighScore[3].Value), 1);
            }

            if (eventList[rowOfEvent].HighScore.Count >= 5)
            {
                labelHSdivername5.Text = eventList[rowOfEvent].HighScore[4].Key.Name;
                labelHSResult5.Text = Math.Round(eventList[rowOfEvent].HighScore[4].Value, 1).ToString();
                labelHSdif5.Text = @"-" +
                                   Math.Round(
                                       (eventList[rowOfEvent].HighScore[0].Value -
                                        eventList[rowOfEvent].HighScore[4].Value), 1);
            }

            if (eventList[rowOfEvent].HighScore.Count >= 6)
            {
                labelHSdivername6.Text = eventList[rowOfEvent].HighScore[5].Key.Name;
                labelHSResult6.Text = Math.Round(eventList[rowOfEvent].HighScore[5].Value, 1).ToString();
                labelHSdif6.Text = @"-" +
                                   Math.Round(
                                       (eventList[rowOfEvent].HighScore[0].Value -
                                        eventList[rowOfEvent].HighScore[5].Value), 1);
            }

            if (eventList[rowOfEvent].HighScore.Count >= 7)
            {
                labelHSdivername7.Text = eventList[rowOfEvent].HighScore[6].Key.Name;
                labelHSResult7.Text = Math.Round(eventList[rowOfEvent].HighScore[6].Value, 1).ToString();
                labelHSdif7.Text = @"-" +
                                   Math.Round(
                                       (eventList[rowOfEvent].HighScore[0].Value -
                                        eventList[rowOfEvent].HighScore[6].Value), 1);
            }

            if (eventList[rowOfEvent].HighScore.Count >= 8)
            {
                labelHSdivername8.Text = eventList[rowOfEvent].HighScore[7].Key.Name;
                labelHSResult8.Text = Math.Round(eventList[rowOfEvent].HighScore[7].Value, 1).ToString();
                labelHSdif8.Text = @"-" +
                                   Math.Round(
                                       eventList[rowOfEvent].HighScore[0].Value -
                                       eventList[rowOfEvent].HighScore[7].Value, 1);
            }

            if (eventList[rowOfEvent].HighScore.Count >= 9)
            {
                labelHSdivername9.Text = eventList[rowOfEvent].HighScore[8].Key.Name;
                labelHSResult9.Text = Math.Round(eventList[rowOfEvent].HighScore[8].Value, 1).ToString();
                labelHSdif9.Text = @"-" +
                                   Math.Round(
                                       eventList[rowOfEvent].HighScore[0].Value -
                                       eventList[rowOfEvent].HighScore[8].Value, 1);
            }


            if (eventList[rowOfEvent].HighScore.Count >= 10)
            {
                labelHSdivername10.Text = eventList[rowOfEvent].HighScore[9].Key.Name;
                labelHSResult10.Text = Math.Round(eventList[rowOfEvent].HighScore[9].Value, 1).ToString();
                labelHSdif10.Text = @"-" +
                                    Math.Round(
                                        eventList[rowOfEvent].HighScore[0].Value -
                                        eventList[rowOfEvent].HighScore[9].Value, 1);
            }
        }

        public void InitializeHighScoreLabels()
        {
            labelHSManOrWomen.Text = @"";
            labelHSheight.Text = @"";
            labelHSklass.Text = @"";

            labelHSdivername1.Text = @"";
            labelHSResult1.Text = @"";

            labelHSdivername2.Text = @"";
            labelHSResult2.Text = @"";
            labelHSdif2.Text = @"";

            labelHSdivername3.Text = @" ";
            labelHSResult3.Text = @" ";
            labelHSdif3.Text = @" ";

            labelHSdivername4.Text = @" ";
            labelHSResult4.Text = @" ";
            labelHSdif4.Text = @" ";

            labelHSdivername5.Text = @" ";
            labelHSResult5.Text = @" ";
            labelHSdif5.Text = @" ";

            labelHSdivername6.Text = @" ";
            labelHSResult6.Text = @" ";
            labelHSdif6.Text = @" ";

            labelHSdivername7.Text = @" ";
            labelHSResult7.Text = @" ";
            labelHSdif7.Text = @" ";

            labelHSdivername8.Text = @" ";
            labelHSResult8.Text = @" ";
            labelHSdif8.Text = @" ";

            labelHSdivername9.Text = @" ";
            labelHSResult9.Text = @" ";
            labelHSdif9.Text = @" ";

            labelHSdivername10.Text = @" ";
            labelHSResult10.Text = @" ";
            labelHSdif10.Text = @" ";
        }

        public void ShowHighOldHighScore(BindingList<Event> eventList, int rowOfEvent)
        {
            InitializeHighScoreLabels();
            labelHSManOrWomen.Text = eventList[rowOfEvent].Gender;
            labelHSheight.Text = eventList[rowOfEvent].JumpHeight + @" meter";
            labelHSklass.Text = eventList[rowOfEvent].Bracket;

            labelHSdivername1.Text = eventList[rowOfEvent].HighScore[0].Key.Name;
            labelHSResult1.Text = eventList[rowOfEvent].HighScore[0].Value.ToString();
            if (eventList[rowOfEvent].CoupleBool)
            {
                labelHScontestname.Text = @"Parhopp";
            }
            else
            {
                labelHScontestname.Text = @"Singelhopp";
            }


            if (eventList[rowOfEvent].HighScore.Count >= 2)
            {
                labelHSdivername2.Text = eventList[rowOfEvent].HighScore[1].Key.Name;
                labelHSResult2.Text = Math.Round(eventList[rowOfEvent].HighScore[1].Value, 1).ToString();
                labelHSdif2.Text = @"-" +
                                   Math.Round(
                                       (eventList[rowOfEvent].HighScore[0].Value -
                                        eventList[rowOfEvent].HighScore[1].Value), 1);
            }

            if (eventList[rowOfEvent].HighScore.Count >= 3)
            {
                labelHSdivername3.Text = eventList[rowOfEvent].HighScore[2].Key.Name;
                labelHSResult3.Text = Math.Round(eventList[rowOfEvent].HighScore[2].Value, 1).ToString();
                labelHSdif3.Text = @"-" +
                                   Math.Round(
                                       (eventList[rowOfEvent].HighScore[0].Value -
                                        eventList[rowOfEvent].HighScore[2].Value), 1);
            }

            if (eventList[rowOfEvent].HighScore.Count >= 4)
            {
                labelHSdivername4.Text = eventList[rowOfEvent].HighScore[3].Key.Name;
                labelHSResult4.Text = Math.Round(eventList[rowOfEvent].HighScore[3].Value, 1).ToString();
                labelHSdif4.Text = @"-" +
                                   Math.Round(
                                       (eventList[rowOfEvent].HighScore[0].Value -
                                        eventList[rowOfEvent].HighScore[3].Value), 1);
            }

            if (eventList[rowOfEvent].HighScore.Count >= 5)
            {
                labelHSdivername5.Text = eventList[rowOfEvent].HighScore[4].Key.Name;
                labelHSResult5.Text = Math.Round(eventList[rowOfEvent].HighScore[4].Value, 1).ToString();
                labelHSdif5.Text = @"-" +
                                   Math.Round(
                                       (eventList[rowOfEvent].HighScore[0].Value -
                                        eventList[rowOfEvent].HighScore[4].Value), 1);
            }

            if (eventList[rowOfEvent].HighScore.Count >= 6)
            {
                labelHSdivername6.Text = eventList[rowOfEvent].HighScore[5].Key.Name;
                labelHSResult6.Text = Math.Round(eventList[rowOfEvent].HighScore[5].Value, 1).ToString();
                labelHSdif6.Text = @"-" +
                                   Math.Round(
                                       (eventList[rowOfEvent].HighScore[0].Value -
                                        eventList[rowOfEvent].HighScore[5].Value), 1);
            }

            if (eventList[rowOfEvent].HighScore.Count >= 7)
            {
                labelHSdivername7.Text = eventList[rowOfEvent].HighScore[6].Key.Name;
                labelHSResult7.Text = Math.Round(eventList[rowOfEvent].HighScore[6].Value, 1).ToString();
                labelHSdif7.Text = @"-" +
                                   Math.Round(
                                       (eventList[rowOfEvent].HighScore[0].Value -
                                        eventList[rowOfEvent].HighScore[6].Value), 1);
            }

            if (eventList[rowOfEvent].HighScore.Count >= 8)
            {
                labelHSdivername8.Text = eventList[rowOfEvent].HighScore[7].Key.Name;
                labelHSResult8.Text = Math.Round(eventList[rowOfEvent].HighScore[7].Value, 1).ToString();
                labelHSdif8.Text = @"-" +
                                   Math.Round(
                                       eventList[rowOfEvent].HighScore[0].Value -
                                       eventList[rowOfEvent].HighScore[7].Value, 1);
            }

            if (eventList[rowOfEvent].HighScore.Count >= 9)
            {
                labelHSdivername9.Text = eventList[rowOfEvent].HighScore[8].Key.Name;
                labelHSResult9.Text = Math.Round(eventList[rowOfEvent].HighScore[8].Value, 1).ToString();
                labelHSdif9.Text = @"-" +
                                   Math.Round(
                                       eventList[rowOfEvent].HighScore[0].Value -
                                       eventList[rowOfEvent].HighScore[8].Value, 1);
            }


            if (eventList[rowOfEvent].HighScore.Count >= 10)
            {
                labelHSdivername10.Text = eventList[rowOfEvent].HighScore[9].Key.Name;
                labelHSResult10.Text = Math.Round(eventList[rowOfEvent].HighScore[9].Value, 1).ToString();
                labelHSdif10.Text = @"-" +
                                    Math.Round(
                                        eventList[rowOfEvent].HighScore[0].Value -
                                        eventList[rowOfEvent].HighScore[9].Value, 1);
            }
        }

        private void FormShowHighscore_Load(object sender, EventArgs e)
        {
            KeyPreview = true;
        }

        private void FormShowHighscore_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
                Close();
        }
    }
}